<script type="text/javascript" SRC="/js/merchant/asn_create.js"></script>
<script type="text/javascript">
$(function(){
	initData(0); //初始化分页数据
	
	$("#tipDialog").dialog({
		autoOpen:false,
		modal:true,
		width:300,
		show:"slide",
		buttons:{
			"Close":function(){
				$(this).dialog("close");
			}
		}
	});
	receivingProduct(<{$receiving_id}>);
});


function sumbitForm(){
    var formData =$('#editForm').serialize();
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/merchant/receiving/create",
		data:formData,
		success: function(json) {
			var html ="";
            if(json.ask=='Success'){
                $("#tipDialog").html('ASNNo: '+json.receiving_code+' Edit success!');
                
            }else{                
				$("#tipDialog").html(' Edit failed!');
            }
			clear();
            $("#tipDialog").dialog("open");
		}
	});
}

function clear(){
	$('[name=instructions]').val('');
	$('#reference_no').html('');
	$('#ProductList').html('');
	$('.all_weight').html('');
}

function checkAll(obj){
	if(jQuery (obj).attr("checked")=='checked'){
		jQuery ('.checked').attr('checked',true);
	}else{
	    jQuery ('.checked').attr('checked',false);
	}
}

function receivingProduct(receiving_id) {
	
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/merchant/receiving/receiving-product",
		data:{
           	'receiving_id':receiving_id
		},
		success: function(json) {
			
			var html = '';
			if(json.ask != 1) {
				html = '<div class="line1">&nbsp;No data returns</div>';
			}else {
										
				$.each(json.result,function(k,v){
					html += '<div class="row height25 productRow'+v.product_id+'">';
					html += '<div class="cell" style="width:15%">'+v.product_sku+'</div>';
					html += '<div class="cell" style="width:20%">'+v.product_title+'</div>';
					html += '<div class="cell" style="width:20%">'+v.category.poc_value+'</div>';
					html += '<div class="cell" style="width:10%"><input type="text" class="inputText" name="op_quantity[]" value="'+v.order_qty+'" style="width:50px;text-align:right" id="op_quantity'+v.product_id+'"  onblur="calWeihgt()"/></div>';
					html += '<div class="cell" style="width:13%" id="product_weight'+v.product_id+'">'+v.product_weight+'</div>';
					
					html +='<div class="cell" style="width:15%;aligh-text:center"><input name="qcChk['+v.product_id+']" type="checkbox" value="1" '+(v.is_qc==1 || v.product_is_qc==1 ? 'checked' : '')+' id="'+v.product_id+'" onclick="isqcCheck(this)" style="margin-top:6px;"></div>';
					
					html +='<div class="cell" style="width:7%; padding-top:5px;"><img src="/images/icon_del.gif" name="button'+v.product_sku+'" onclick="deleteProduct(this)" class="cursor" title="Delete"/><input type="hidden"  name="product_id[]" class ="product_id" value="'+v.product_id+'" /><input type="hidden"  name="op_id[]" value="0" /></div>';
					html += '<div class="clearFloat"></div>';
					html += '</div>';
				});	
				$('#reference_no').html(json.receiving.ref_id);
				$('[name=instructions]').val(json.receiving.description);
				$('[name=receiving_id]').val(json.receiving.receiving_id);
			}
			$('#ProductList').append(html);	
			calWeihgt();		
		}	//success
	});

}


</script>
<div class="position"><a>Merchant Center</a> > <a>Operations</a> > Send to Warehouse</div>

<form id="editForm"  method="POST" >
<h4>Create ASN (Advanced Shipping Notice)</h4>
<div style="margin-bottom:10px">
	<p>
	You need to create an ASN (Advanced Shipping Notice) to notify us of your incoming stock.
	Input the quantity of each product which you will be sending and then click the "Create ASN" button.
	Note: If your product is not listed below, Try to <a href="/merchant/product/create" style="text-decoration:underline" > Create New Product</a> first and then 	make sure it was Activated.
	</p>
</div>

<div class="tab-div">

	<div class="row">
		<div class="right"  style="width:20%;padding-left: 5px; font-size:14px;font-weight:bold">Reciving List:</div>
		<div class="middle">			
			<span class="button-2"  onclick="OpenProductDiv()">Add Product</span>
			<span class="red">&nbsp;&nbsp;</span>
		</div>
		<div class="right"></div>
	</div>
	
	<div class="row "  id="OrderProduct">
		<div class="row height25 row-header">
            <div class="cell sort" style="width:15%" >SKU</div>
			<div class="cell sort" style="width:20%" >SKU Name</div>
			<div class="cell sort" style="width:20%" >Category</div>
			<div class="cell sort" style="width:10%" >Quantity</div>
			<div class="cell sort" style="width:13%" >Weight</div>
            <div class="cell" style="width:15%">Quality Control</div>
			<div class="cell2" style="width:7%">Action</div>
		</div>
		<div id="ProductList"  class="row"></div>
	</div>
	
	<div class="row height25">
		<div class="cell" style="width:80%;text-align:right" >Total Weight&nbsp;&nbsp;&nbsp;</div>
		<div class="cell2 all_weight"  style="width:20%;text-align:left" ></div>
	</div>

</div>

<h4>Additional Info</h4>
<div class="tab-div">
    <div class="row">
		<div class="right"  style="width:20%;padding-left:5px;padding-top:8px;">Reference No:</div>
    	<div class="middle" style="padding-bottom:6px;"><span id="reference_no"></span>
    <!--   <input type="text" width="45" class="inputText" name="reference_no" value=""/>-->    		
    		<span class="red">&nbsp;&nbsp;</span>
    	</div>
    	<div class="right"></div>
	</div>

	<div class="row" style="padding-left:5px;padding-top:5px">
		<div class="right"  style="width:20%;height:95px;">Special Instructions:</div>
    	<div class="middle">
    		<textarea cols="38" rows="5" name="instructions" ></textarea>
			<input type="hidden" name="receiving_id" value="" />	<!-- receiving_id，修改状态时不为空-->
    		<span class="red">&nbsp;&nbsp;</span>
    	</div>
    	<div class="right"></div>
	</div>
    
    <div class="row" style="height:40px;align:center">

    	<div style="margin-top:10px;margin-left:150px">    		
    		<span class="button-2"  onclick="sumbitForm()"> Edit </span> 
    	</div>
    </div>
</div>
</form>

<div class="prdouctDiv" style="display:none" title="Product List">
<{include file='merchant/orders/warehouse-products-list.tpl'}>
</div>

<div id="tipDialog" style="display:none" title="Tip"></div>